package alipay_sdk

import (
	"github.com/smartwalle/alipay"
	"rpcSrv/configs"
	"sync"
)

/*
正式：
"app_id": "2019071765857502",
      "private_key": "MIIEpQIBAAKCAQEA2E/oHOabMBkn1bgeoVunzFZHDgqKTDMfYXqFYdIhw/6yT6nl9mKP4wlcRRu/RDUvubhxroM+NBHvDEabhV7OV5Yc7DWeuEWkxJxDwNNleyMeFqVlC+IjRluoJSkjKHTmUVkEafE0EoAjOUcw/8p0p5cioet39CwSrif4pXJC2CzQk7x9+zvxgPv28AP8ixCiHM8UnQmR+ir3mAITLj/eZ+1PRiiw4OKzIT+UL0stSj5uh+2AnmFHzg5SJo0QGDzPwti2WMacoxY+xjspx4PVP6Md41DqfhPD6SDof8AO4xSaPo9SKVkP080qPmjzWILiqoEa4ZxN9FW/5CCoIea5nQIDAQABAoIBAQCMbKthf69FNT9v9dwkoiy3cVclXWBUgWegz3ohe9mhtAmrv77jCS8hk2UMFCxBqkl2Rq++O8M46F+IV5oEpfxMTc4u5cxJEiUZ4dv2JQYfPzf8OZj0cvS1azEoFqGVVPZj3ucHo6dLT1YOjBHaLGM4nNvFw+gWYjoqRxaaySdtz8+yhuRk48EXHw2y0PFmAVkJi4M8V9A8Qxu8VBvUc3GmNpdOtVpUvaJmItO6dE5OwJCD+BFYZk8VwFM9ws3ktmd+65j+zTy2Cnb8y9MqjD3YaHhJwnQfmyaOH7e8iGikop7uDqjq9b2QgOE55TqImZczAvi1oAein9yL8mM3L4IBAoGBAPzL6xbkhvVWywa9RlKdv603lAPOr0aU2LBDWg+MhqLA3LLHs20KtPl8D3WRUXV6BJFSR+94AlRGknHZW1rIaZQtpdL8daym3SjbZyNh2vhHqq5JbS4OBrejQrLYVmRLRWdWdyYUcYN3zWSUIANsIZf49I9V9i8aTmZD1vJseJOBAoGBANsNoatGxWl3nPKFiHoRHSSChZ6bdx6Gf3k46wtcRA9vP49f8OrXoQNZz0Y1UyiTF6xJbwUB6LSHez6SZCb0bDYzln8mAP8Uo7pAFiK/akUzMH5dqM4DchTBZgw69vK9DEgZ2k9YML5tOsWhY4lWfewwwbhshIf6wlH6vogt8AQdAoGAQ+CJHht8dVG5r/SQdkxvFBaRQrhzbbM3v5RGEVi9KeQ5HjPq5IN0dmyuRfYf9jguE8sRD6ackX5lgfZHxkd7udLL7Kvm+NXRGlBXEDQNNI8hsCx9CVmwygwnM5hNEh734rhfw7THifJYDwKK2gBlwMWS/Q2qzZj1phXfGDax5YECgYEAu7AVWqS71x8mueHSSwzI1JSFGp4IVX5WUK6FLemzYyol4poI2Z9CFZXo9DYSd4x41yTgXAEDu1LuNXHHIF2DLnnLNEyCxAySMK5iiQlLa9ltboifb00ifUgsQMRw/REgKdME68Ebmr4KgnVCzNTv9eTcx0Er2TrxLr7Sa+o4Yb0CgYEAu7ddlrdShA6LBo6QbkggURk/aUEevIfKr12Zy70Ym2Ii8ofqAcIGqclF8/JoQE+IeuEykoYkmDe/zWVbymb2cMJX4yGh4SJYLDSdFadG6LNdZW0jKHTS7W+otDCu9Okkt27Ezwq292vLBdjCJTZDZh/WRxh01UkZjg+aFY4xMEw=",
      "ali_public_key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhAZ5JdER2hT6Ni2b0MNHjNFhC7kf40psIfdtJdfMhHOzE2c7h5J8dBkG1tXggsgO+ADUjMjloZWq/xUr9ZMVvHhsOhc0exZ2RdReUUv7gfzWZTdkcuEy/Ated5dOkHTl89P7aEnryP1lFjkadcYf/J9mELcd2/setmLxNsYT0ru3R/rb++67tblO7enthKpyVlgVjLrhT1W8uIZFaeJTbbH6szJPrz+uT5s2U5UP9k3TLTeSUw/CSnd0R9eM2feFrYje4MCqqTr1LZf8bYD2U+Y3+WcYQtOr8j1DyxyX01NR7inQLpMDI9+U2VBo2vXRWpBbJY3+sfssza5gwp3KDwIDAQAB",
*/

var (
	err          error
	cli          *alipay.AliPay
	once         sync.Once
	aliPayConf   = configs.GetAliPayConf()
	appId        = aliPayConf.AppId
	privateKey   = aliPayConf.PrivateKey
	aliPublicKey = aliPayConf.AliPublicKey
	aliPayProd   = aliPayConf.AliPayProd
)

func init() {
	once.Do(func() {
		isProd := false
		if aliPayProd == "1" {
			isProd = true
		}
		cli= alipay.New(appId, aliPublicKey, privateKey, isProd)
	})
}

func GetAliPayCli() *alipay.AliPay {
	return cli
}
